import req from "/@/api/req";
import type { LockModel, LogoutParams, UpdateAccModel } from "./models";

export enum Api {
  addUser = "api/system/users/addUser",
  modifyUser = "api/system/users/modifyUser",
  removeUserAccountByUserIds = "api/system/users/removeUserAccountByUserIds",
  getAccountPage = "api/system/users/page",
  getUsersByAccount = "api/system/users/getUsersByAccount",
  // 账号操作
  resetPassword = "api/system/users/resetPassword", // 重置密码 个人中心使用
  updatePassword = "api/system/users/updatePassword", // 更新密码
  lockUserByUserId = "api/system/users/lockUserByUserId", // 锁定账号
  logout = "api/system/oauth/logout",
  //登录日志
  oauthLogsPage = "api/system/oauthLogs/page",
  oauthLogsExport = "api/system/oauthLogs/export",
  //修改用户名
  updateUserName = "api/system/users/updateUserName",
}

// 重置密码
export function resetPassword(data: UpdateAccModel) {
  return req.post<boolean>({
    url: Api.resetPassword,
    data,
  });
}
// 更新密码
export function lockUserByUserId(data: LockModel) {
  return req.post<boolean>({
    url: Api.lockUserByUserId,
    data,
  });
}

//退出登录
export function logout(data: LogoutParams) {
  return req.post<boolean>({
    url: Api.logout,
    data,
  });
}

export function updateUserName(data: { userId: string; userName: string }) {
  return req.commonPost(Api.updateUserName, data, { useGlobalLoading: false });
}

export function updatePassword(data: {
  userId: string;
  confirmPassword: string;
  oldPassword: string;
  password: string;
}) {
  return req.commonPost(Api.updatePassword, data, { useGlobalLoading: false });
}
